<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="content-type" content="text/html; charset=UTF-8" />
    <title>基础数据管理-项目信息新增</title>
    <script src="/scripts/boot.js"></script>
</head>
<body class="bg-white">
<div id="viewForm">
    <!--<div class="title-info mb-20"><span>基本信息</span></div>-->
    <table class="table-bg" border="0" cellpadding="1" cellspacing="1" style="width:100%;table-layout:fixed;">
        <colgroup>
            <col width="135px"></col>
            <col width="50%"></col>
            <col width="135px"></col>
            <col width="50%"></col>
        </colgroup>
        <tr>
            <td class="text-titlebg">
                <span class="color-red">*</span>角色名称
            </td>
            <td>
                <input type="hidden" class="mini-hidden" name="id"/>
                <input type="text" name="roleName" class="mini-textbox w250" required="true" errorMode="none" onvalidation="onNullValidation" requiredErrorText="请输入" vtype="maxLength:48"/>
            </td>

            <td class="text-titlebg title noEmpty">
                <span class="color-red">*</span>人员
            </td>
            <td>
                <!--<input type="text" name="userIds" class="mini-textbox w250" required="true" errorMode="none" onvalidation="onNullValidation" requiredErrorText="请输入" vtype="maxLength:48"/><span class="search-span" onclick="view.person()"></span>-->
                <input name="userIds" id="userIds" class="mini-treeselect w250" multiselect="true" onbeforenodeselect="common.beforenodeselect" expandOnLoad="true" showTreeIcon="true" valueField="id" textField="name"   parentField="pid" required="true" errorMode="none" onvalidation="upChoseError" requiredErrorText="请选择"/>
                <!-- <select id="" name="status" class="mini-combobox w250" url="" textField="name" valueField="id" errorMode="none" onvalidation="onChoseValidation" required="true" requiredErrorText="请选择"></select> -->
            </td>
        </tr>
        <tr>
            <td class="text-titlebg">
                <span class="color-red">*</span>是否可用
            </td>
            <td>
                <div class="mini-radiobuttonlist w250" name="available" repeatItems="1" repeatLayout="table" repeatDirection="vertical" textField="text" valueField="id" value="0" data="[{ id: '0', text: '是' }, { id: '1', text: '否'}]" ></div>
            </td>
            <td class="text-titlebg title noEmpty">
                <span class="color-red">*</span>授权项目
            </td>
            <td>
                <select id="itemIds" name="itemIds" class="mini-combobox w250" multiselect="true" ajaxType="post" url="/item/list" textField="name" valueField="id" required="true" errorMode="none" onvalidation="upChoseError" requiredErrorText="请选择"></select>
                <!--<input name="itemEndDate"  id="itemEndDate" class="mini-datepicker w250" allowInput="false" errorMode="none" onvalidation="onChoseValidation" required="true" requiredErrorText="请选择"/>-->
            </td>
        </tr>
        <tr>
            <td class="text-titlebg noEmpty">备注</td>
            <td colspan="3" class="wp">
                <textarea name="marker" class="mini-textarea wtextarea" emptyText="" errorMode="none"></textarea>
            </td>
        </tr>
    </table>
    <div class="chose-toolbar">
        <a class="chose-button" onclick="CloseWindow('close')">取消</a>
        <a class="chose-button save-button" onclick="view.save()">保存</a>
    </div>
</div>
<script type="text/javascript">
var post_flag,form,state,datas;
var view = {
    init: function () {
        common.loadTree({
            success : function(data){
                //获取评价人
                var userIds = mini.get("userIds");
                userIds.loadList(data, "id", "pid");
            }
        });
        post_flag = false; //设置一个对象来控制是否进入AJAX过程
        mini.parse();
        form = new mini.Form("#viewForm");
    },
    //保存
    save: function () {
        form.validate();
        if (form.isValid() == false) return;
        if (post_flag) return;
        var data = form.getData();//获取表单多个控件的数据
        post_flag = true;
        $.ajax({
            url: (state=="new"?"/role/save":"/role/edit?id=" + data.id),
            type: "post",
            data: data,
            success: function (msg) {
                post_flag = false;
                CloseWindow("ok");
            },
            error:function (errorMsg) {
                post_flag = false;
                var msg  = JSON.parse(errorMsg.responseText);
                common.prompt(msg.message);
            }
        });
    },
//    数据展示
    SetData: function (data) {
        data = mini.clone(data);
        state = data.state;
        if(data.state=="edit"){
	        $.ajax({
	            url:"/role/info?id=" + data.id,
	            type: "post",
	            success: function (text) {
	                //跨页面传递的数据对象，克隆后才可以安全使用
	                datas = mini.decode(text);   //反序列化成对象
	                form.setData(datas);             //设置多个控件数据
                    setTimeout(function(){
                        mini.get("userIds").setValue(datas.useridss);
                        mini.get("itemIds").setValue(datas.itemidss);
                    },1000);
	            },
                error:function (errorMsg) {
                    var msg  = JSON.parse(errorMsg.responseText);
                    common.prompt(msg.message);
                }
	        });
        }else{
        	$('input[name=id]').val("");
        }
    },
    person:function () {
        mini.open({
            url: "/common/person.html",
            title: "选择人员", width: 1100, height: 500,
            onload: function () {

            },
            ondestroy: function (action) {
                grid.reload();
            }
        });
    }
};
view.init();
</script>
</body>
</html>